-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixing Github contribution error #650
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While the backoff algorithm is good, you are doing a lot here for a simple fix. Because this is likely to be stuck in review, I'd encourage you to create another PR with the minimal fix so that we can merge it quickly. After that, we can talk about other improvements, including the back-off algorithm in this PR.
$config = $config_factory->get('ct_github.settings'); | ||
$token = $config->get('github_auth_token'); | ||
$client = new Client(); | ||
$client->authenticate($token, NULL, AuthMethod::ACCESS_TOKEN); | ||
$client = (strlen($token) === 40) ? (new Client())->authenticate($token, NULL, AuthMethod::ACCESS_TOKEN) : NULL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not all tokens are 40 characters in length. Fine-grained tokens are longer.
@@ -40,13 +41,14 @@ class GithubQuery { | |||
* @param \Drupal\Core\Cache\CacheBackendInterface $cacheBackend | |||
* The injected cache backend service. | |||
*/ | |||
public function __construct(ConfigFactory $config_factory, CacheBackendInterface $cacheBackend) { | |||
public function __construct(ConfigFactory $config_factory, CacheBackendInterface $cacheBackend, LoggerChannelFactoryInterface $loggerFactory) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra whitespace. This should have been caught by the CI. This is another issue but let's not introduce this here.
if ($e->getMessage() === 'Bad credentials') { | ||
$this->logger->error('GitHub API error: Bad credentials. Please check the credentials.'); | ||
return NULL; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it likely that we will get bad credentials here? Shouldn't this have been caught in authenticate
method itself?
|
||
// Handle other errors with backoff | ||
$retryCount++; | ||
$this->logger->warning("GitHub API request failed. Retry $retryCount/$maxRetries. Error: " . $e->getMessage()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not log this at warning
when we are going to try again. We can log this at info
or notice
level maybe.
if($userContributions){ | ||
$issues = array_map(function ($issue) { | ||
return new Issue($issue['title'], $issue['url']); | ||
}, $userContributions['data']['user']['issues']['nodes']); | ||
return $issues; | ||
return $issues;} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whitespace error. Again this should have been caught in the CI.
if ($plugin_id === "github") { | ||
return; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a code smell. The ct_manager
should not have to know about ct_github
.
@Yemaneberhan-Lemma, this needs to be rebased. |
Handling the issue